home *** CD-ROM | disk | FTP | other *** search
- CH 10 − UTILITIES
- =================
- All the procedures described in this chapter are initiated by choices from
- the Utilities submenu of the icon-bar menu to examine and alter the
- structure of an existing database. Note that, if passwords have been set,
- you need to enter the database with the “Manager”-level password to obtain
- access to this submenu.
-
- 10.1 Changing the Primary Key
- ==============================
- The primary key of a database is determined when it is created, but is not
- fixed for all time. The New primary key choice displays the same dialogue
- box as used for creating the primary key in the first place, but with the
- addition of two radio buttons, whose function is described below. The
- present key structure is shown. Simply alter it to what you require and
- click on Create or type Return.
-
- Normally the first of the two radio buttons (Retain subfile structure) is
- selected, making the records appear in the same subfiles as before. In this
- case, any additional indices will still be valid. If you deselect this radio
- button with ADJUST (i.e. have neither button selected) then all the records
- will be placed in the currently selected subfile.
-
- Selecting the second button (Ignore old primary key) also places the records
- in the current subfile, but has the additional effect of recovering
- “deleted” records, i.e. records which are still lurking in the Database file
- but aren’t in the primary key index. One important circumstance under which
- you would need to use this option is when the primary key index is lost or
- corrupted.
-
- NOTE: You might have a Database file but no PrimaryKey file at all. This
- could happen if you have, for example, created a suitable text file and then
- set its type to Database. To build a primary key for such a file the only
- valid setting for the radio buttons is the one just described, i.e. second
- button selected. To enforce this mode both radio buttons are shaded.
-
- 10.2 Adjusting the record format
- =================================
- Minor changes to the screen layout can be made without having to rebuild the
- database. Choose Adjust format and you will be presented with the blank
- record screen. Clicking MENU over this brings up the same menu as you used
- to create the screen originally, but the Field definition window has some
- options shaded. Thus you can’t delete fields, add new ones or alter the data
- lengths, but you can re-position fields, change descriptors and tags, and
- alter the visible lengths. When you have finished the changes, choose the
- last option on the menu; Quit design.
-
- 10.3 Changing the record format
- ================================
- This is more drastic, but it is not always possible to foresee future needs
- and you may have to introduce a new field or lengthen an existing one. To do
- so you must rebuild the whole database. You will need to create a new
- application shell with the new Form file inside it. The best way to do this
- is to open the new database directory, copy the old Form file into it, then
- double-click on the new “database”. As no PrimaryKey or Database file exists
- yet you will be able to modify the screen design as you wish. You should
- not, however, go on to complete the empty database (i.e. don’t choose
- Default database or click on the Create button in the Key structure window)
- − simply save the Form file using the menu choice provided.
-
- With the old database open, choose New record format. Drag the new database
- to the large arrow icon in the displayed window and click on Reformat. The
- database will then be rebuilt. Make sure you have plenty of disc space
- available before doing this as the original remains intact so you need room
- for both it and the new one. Data from a field in the old database is copied
- to a field in the new one with the same tag. The new Form file must
- therefore retain the same tags as the old for data which is to be common to
- both. If a tag exists in the old Form file but not in the new one Powerbase
- will assume that the relevant field has been deleted and data present in
- that field in the old database will not be transferred. A tag which is
- present in the new database but not in the old is assumed to be a
- newly-introduced field and will therefore be left blank.
-
- When the process is complete you will find that the new database contains
- all your old data but in the new record format. Links to validation tables
- are preserved but formulae for self-calculating fields will need to be
- re-initialised by opening the formula window for each and clicking OK (see
- 6.1.1).
-
- 10.4 Merging two databases
- ===========================
- Two databases may be merged provided they have the same record structure.
- With the first database open, select Merge database and drag the second
- database to the arrow icon in the displayed window. Powerbase will check
- that the two record formats are identical and report an error if they
- aren’t. If the open database has insufficient free space to hold the merged
- records it is automatically extended. An option switch determines the
- action taken with regard to Sequence number fields (see 8.4.1).
-
- Two radio buttons are also present, as in the dialogue box for rebuilding
- the primary key, and their functions are essentially the same. Having the
- first button selected merges records into the same subfiles as those they
- occupied in the source database. Having neither selected merges records into
- the current subfile of the open database, regardless of where they are in
- the source database. Having the second button selected does the same, but
- also imports records which were “deleted” in the source database.
-
- 10.5 Changing the Database Length
- ==================================
- Lengthening a database is often required, shortening is less common, but
- both are easily accomplished. Change length leads to a window with two
- writable icons. The first specifies the new database length. You will be
- warned if, when shortening a database, any records being removed are not
- blank. The data they contain might belong to deleted records, but might not.
- You have been warned! The other writable icon determines the number of
- records by which the database will be lengthened each time it becomes full.
- If this value is zero no automatic lengthening occurs; a warning is
- displayed instead.
-
- 10.6 Inspecting and balancing index trees
- ==========================================
- Print index lets you examine the structure of the current index to find out
- how many keys are present in each level. The ideal numbers in a
- perfectly-balanced index tree are 1, 2, 4, 8, 16, 32, 64, 128 etc. (i.e.
- powers of 2, beginning with 20.) A submenu gives you the option of printing
- the actual keys, positioned according to the level they occupy in the tree,
- or printing only the total number of nodes in each level.
-
- The data printed applies to the current subfile of the current key and is
- output to a screen window from which it may be saved in the same way as any
- other list. (If you have printed the keys themselves then double-clicking
- with SELECT on any key will call up the associated database record.)
-
- If the tree is very deep and straggly it may not be possible to show all of
- it. The maximum number of levels which can be shown is in fact 40, including
- the root. Using option (1) above causes keys which cannot be displayed in
- their correct positions to appear down the left hand side of the window with
- a note indicating the level in which they occur.
-
- If the tree is very unbalanced, i.e. if it departs dramatically from the
- “powers-of-two” pattern described above and, especially, if there is an
- enormous number of levels with only 1 or 2 keys in each, you are advised to
- balance it using the Balance index choice*. It is also possible to make
- Powerbase balance the index automatically at regular intervals. To turn on
- auto-balancing choose Preferences from the icon-bar menu. Select the
- Balance every <n> records switch, placing your chosen value of n in the
- writable icon provided, then click on Accept.
-
- Auto-balancing is most likely to be used when a large number of records are
- being entered in primary-key-order. This will happen if you are entering
- data from a lot of forms in alphabetical order of name where name is the
- primary key. It is also very likely to happen when importing CSV files as
- these are often ordered according to the data item which becomes the primary
- key field of the database record.
-
- 10.7 Finding duplicate primary keys
- ====================================
- Wherever possible a primary key should be chosen so as to be unique. Where
- duplication of the primary key might occur the designer of the database can
- decide either to allow or forbid it (see 11.2.1). If duplicate keys are
- permitted it is sometimes useful to have a list of them. Such a list is
- created by Find duplicates and may be saved as a text file.